<template>
  <div>
    <div class="screen"> 
      <t-tooltip :content="isFullscreen ? '退出全屏': '全屏' ">
        <img v-if="isFullscreen" src="../../assets/images/icon_sreefull/tuichuquanping.png" @click="isclick"/>
        <img v-else src="../../assets/images/icon_sreefull/quanping-xian.png" @click="isclick">
      </t-tooltip>
    </div> 
  </div>
</template>

<script>
import screenfull from "screenfull";

export default {
  name: "Screenfull",
  components: {
   
  },
  data() {
    return {
      isFullscreen: false,
    };
  },
  mounted() {
    this.init();
  },
  beforeDestroy() {
    this.destroy();
  },
  methods: {
    isclick() {
      // 判断是否支持
      if (!screenfull.enabled) {
        this.$message({
          message: "不支持全屏",  
          type: "warning"
        });
        return false;
      }
      screenfull.toggle();
    },
    change() {
      this.isFullscreen = screenfull.isFullscreen
    },
    init() {
      if (screenfull.enabled) {
        screenfull.on('change', this.change)
      }
    },
    destroy() {
      if (screenfull.enabled) {
        screenfull.off('change', this.change)
      }
    },
  }
};
</script>

<style scoped>
.screen {
    width:25px;
    height:25px;
    margin-right: 5px;
    cursor: pointer;
    line-height:25px;
    /* vertical-align: 10px; */
    color: #5a5e66;
}
.screen img {
    width: 100%;
    height: 100%;
}
.screen:hover {
    cursor: pointer;
    background: rgba(0, 0, 0, 0.025);
    transition: background 0.3s;
}
</style>